home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / music / fft4wav3.zip / C_SOURCE.ARJ / VISUAL.C < prev   
Text File  |  1994-11-22  |  23KB  |  597 lines

  1. #include <dos.h>
  2. #include <alloc.h>
  3. #include <time.h>
  4. #include <math.h>
  5. #include <graphics.h>
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <conio.h>
  9. #include <vga&bmp.h>
  10. #include <string.h>
  11. #define   MY_SIZE     double   /* or float or long double */
  12. #define   MY_TYPE     huge     /* or far if data fits in two 64 K segments */
  13.  
  14. extern unsigned _stklen;
  15.  
  16. extern int grafdriver,Grafikmodi;                     //in Ruhe lassen
  17. extern int MausX,MausY;                               //GrafikCursor-Position
  18. extern int maxx,maxy;                //maximaler Wert fuer X/Y im Grafikmodus
  19. extern int Farbe[20];    // 0-9=Farbe,10-19=Reserviert, siehe auch INI-Datei!
  20. extern int  maxcommands;                    //Anzahl der Commandline Optionen
  21. extern char CommandLine[10][80];            // ARRAY mit Commandline Optionen
  22. extern int  Aktuell;                      // Nummer der ausgewählten Funktion
  23. extern char AktuellText[81];              //  Name  der ausgewählten Funktion
  24. extern char AktuellName[81];                       //Name der gewählten Datei
  25. extern double Puffer[1024];                         //Bildschirm-Daten-Puffer
  26. extern int PufferMAX;                  //Bildschirm-Daten-Puffer Anzahl Werte
  27. extern double huge *real;        //Pointer auf Real - Array
  28. extern double huge *imag;        //Pointer auf Imag.- Array
  29. extern unsigned long size;       //maximale Anzahl der Arrayelemente
  30. extern long AnzahlNormal;              //Anzahl Abtastwerte   wenn Stereo=0
  31. extern long AnzahlReal;                //Anzahl Realwerte     wenn Stereo=1
  32. extern long AnzahlImag;                //Anzahl Imaginärwerte wenn Stereo=1
  33. extern int Stereo;                     //Real & Imaginär, Stereo=1;
  34. extern int Nykill;                     //Nyquistkr=Samplerate/2 wenn Nykill=0
  35. extern int FFTflag;                    //Zeitbereich = 0, Frequenzbereich = 1
  36. extern double lr,or,ur,rr;             //Randwerte für GrafikCursorShow...
  37. extern double Samplerate;              //Abtastrate im Zeitbereich
  38. double div_Y=1.0;                      //Amplitude eines DIV
  39. double Xrange,YrangeMAX,YrangeMIN,Yoff; //Scaleing Info...
  40.  
  41.  
  42.  
  43.  
  44.  
  45. extern void Kill();
  46. extern void Grafik(int o);
  47. extern void Maus(int o);
  48. extern void saveBMP(int o);
  49. extern void Zeichensatz();
  50. extern int GrafikCursor(int b);
  51. extern int GrafikCursorShow(int b,int z);
  52. extern int GrafikCursorDraw(int b);
  53. extern int GrafikCursorLine(int Xx,int Yy);
  54. extern int GrafikCursorWindow(int Xx,int Yy);
  55. extern void MausPosition(int xx,int yy);
  56. extern int inkey(int o);
  57. extern void zeigeHilfe(char *dateiname);
  58. extern int zeigeMenu();
  59. extern int huge lese_INI_Datei();
  60. extern int zeigeDatei(char *dateiname);
  61. extern void Directory(char *dirEXT,int o);
  62. extern void SOUND_Import(int B16);
  63. extern int loadALL(char *dateiname);
  64. extern int saveALL(char *dateiname);
  65. extern void Import(int o);
  66. extern void Export(int o);
  67.  
  68.  
  69.  
  70.  
  71. void fuellen(int ArT)   //Eingabe von Daten mit hilfe der Maus...
  72. {                       //fuellen(0)  digitale Interpolation
  73.  int a,b,c;             //fuellen(1)  lineare Interpolation
  74.  double e,f;            //fuellen(2)  SIN-Treppen Interpolation
  75.  inkey(0);              //fuellen(3)  Spezial Interpolation
  76. gitter_Loop:            //Looping:    Eingabe der Stützstellen...
  77.  setcolor(Farbe[3]);
  78.  if(Farbe[19])outtextxy(9,maxy-9,"R  I  B  F9  F10  Del  Esc  Enter");
  79.  c=GrafikCursorDraw(20);
  80.  if(c==27)return;             //Abbruch?
  81.  if(c>27)
  82.          {
  83.           Kill();             //Bildschirm löschen
  84.           if((c=='i')||(c=='r')||(c=='b')) // imaginär, real oder beide zeigen
  85.             {
  86.              bothLOOP:
  87.              if(c=='r')b=AnzahlReal; else b=AnzahlImag;
  88.              if(b>maxx)b=maxx;
  89.              for(a=0;a<b;a++) { if(c=='r')Puffer[a]=real[a]; else Puffer[a]=imag[a]; }
  90.              f=0; for(a=0;a<b;a++)if((e=fabs(Puffer[a]))>f) f=e;
  91.              a=maxy/2;  e=a;  f=e/f;  e=e+1.0;  setcolor(Farbe[3]);
  92.              for(a=1;a<b;a++)line(a-1,e-f*Puffer[a-1],a,e-f*Puffer[a]);
  93.              for(a=0;a<=maxx;a+=6)putpixel(a,e,Farbe[2]);
  94.              if(c=='b') { c='r'; goto bothLOOP; }
  95.             }                                       //Gitter zeichnen
  96.           for(a=0;a<=maxx;a+=(maxx+1)/16)for(b=0;b<=maxy;b+=4)putpixel(a,b,Farbe[2]);
  97.           for(a=0;a<=maxy;a+=(maxy+1)/12)for(b=0;b<=maxx;b+=4)putpixel(b,a,Farbe[2]);
  98.           for(b=0;b<=maxx;b+=4)putpixel(b,maxy,Farbe[2]);
  99.           for(b=0;b<=maxy;b+=4)putpixel(maxx,b,Farbe[2]);
  100.           putpixel(maxx,maxy,Farbe[2]); goto gitter_Loop;
  101.          }
  102. setcolor(Farbe[0]);  if(Farbe[19])outtextxy(9,maxy-9,"R  I  B  F9  F10  Del  Esc  Enter");
  103.  Filter(ArT);      //in Puffer einlesen, fehlende Stützstellen Interpolieren!
  104. setcolor(Farbe[3]);  if(Farbe[19])outtextxy(9,maxy-9,"F9 F10");
  105.  for(a=0;a<PufferMAX;a++)putpixel(a,Puffer[a],Farbe[2]);
  106.  c=inkey(2);      if((c==323)||(c==324))saveBMP(c-323);    //ausdrucken?
  107.  Kill();      setcolor(Farbe[1]);      inkey(0);
  108.  
  109.  for(a=1;a<PufferMAX;a++)line(a-1,Puffer[a-1],a,Puffer[a]);
  110.  
  111. lowpass_Loop:                       //Eingabe glätten / Nullpunkt_setzen
  112.  setcolor(Farbe[2]);
  113.  if(Farbe[19])outtextxy(400,maxy-9,"Mouse_L: DC=0   Mouse_R: DC=?");
  114.  setcolor(Farbe[3]);
  115.  if(Farbe[19])outtextxy(9,maxy-9,"1 2 3 4 5 6     7 8 9 0     Esc");
  116.  c=GrafikCursor(50);
  117.  inkey(0);
  118.  if(c==27)return;
  119.  if((c>='0')&&(c<='9'))            //glätten?
  120.                   {
  121.                    a=c-'0';
  122.                    if(a>0) b=2<<a;   //RC-Filter
  123.                    if(a==7)b=-4;     //symetrisches Filter
  124.                    if(a==8)b=-8;     //symetrisches Filter
  125.                    if(a==9)b=-16;    //symetrisches Filter
  126.                    if(a==0)b=-32;    //symetrisches Filter
  127.                    Filter(b);    Kill();
  128.                    setcolor(Farbe[1]);
  129.                    for(a=1;a<PufferMAX;a++)
  130.                        {  line(a-1,Puffer[a-1],a,Puffer[a]);  }
  131.                    goto lowpass_Loop;
  132.                   }
  133. if(c==2)             //Nullpunkt Korrektur
  134.          {
  135.           a=MausX,b=MausY;
  136.           c=GrafikCursorLine(MausX,MausY);
  137.           inkey(0);
  138.           if(c==27)return;
  139.           e=MausY-b;
  140.           e=e/(MausX-a);
  141.           f=b-e*a;
  142.           Kill();
  143.           setcolor(Farbe[2]);  settextstyle(0,0,4);
  144.           outtextxy(102,(1*maxy)/6,"Reell");
  145.           outtextxy(102,(3*maxy)/6,"Real");
  146.           outtextxy(102,(5*maxy)/6,"Imaginär");
  147.           for(a=0;a<=PufferMAX;a++)Puffer[a]=Puffer[a]-(e*a+f);
  148.           c=maxy/2;  line(0,c,maxx,c);  setcolor(Farbe[3]);
  149.           outtextxy(100,(1*maxy)/6-2,"Reell");
  150.           outtextxy(100,(3*maxy)/6-2,"Real");
  151.           outtextxy(100,(5*maxy)/6-2,"Imaginär");  setcolor(Farbe[1]);
  152.           for(a=1;a<PufferMAX;a++) line(a-1,c+Puffer[a-1],a,c+Puffer[a]);
  153.          }
  154. else                        //kein Gleichanteil (DC=0)!
  155.     {
  156.       e=0,f=PufferMAX;  for(a=0;a<PufferMAX;a++)e=e+Puffer[a];
  157.       e=e/f;    for(a=0;a<PufferMAX;a++)Puffer[a]=Puffer[a]-e;
  158.       Kill();
  159.       setcolor(Farbe[2]);  settextstyle(0,0,4);
  160.       outtextxy(102,(1*maxy)/6,"Reell");
  161.       outtextxy(102,(3*maxy)/6,"Real");
  162.       outtextxy(102,(5*maxy)/6,"Imaginär");
  163.       line(0,e,maxx,e); setcolor(Farbe[3]);
  164.       outtextxy(100,(1*maxy)/6-2,"Reell");
  165.       outtextxy(100,(3*maxy)/6-2,"Real");
  166.       outtextxy(100,(5*maxy)/6-2,"Imaginär"); setcolor(Farbe[1]);
  167.       for(a=1;a<PufferMAX;a++) line(a-1,e+Puffer[a-1],a,e+Puffer[a]);
  168.     }
  169. a=(maxy+1)/12;  e=-a;                                   //auf div_Y scalieren
  170. for(a=0;a<PufferMAX;a++)Puffer[a]=div_Y * Puffer[a]/e;
  171. c=GrafikCursor(100);
  172. inkey(0);                                //daten umweltfreundlich endlagern ?
  173. if(c==27)return;
  174. c=(3*MausY)/maxy;
  175. FFTflag=0, Stereo=1, Nykill=0;
  176. if(c==0)
  177.         {                                //reelle Daten
  178.          for(a=0;a<PufferMAX;a++)
  179.             {
  180.              if ((a&1)) imag[a/2] = Puffer[a];
  181.              else       real[a/2] = Puffer[a];
  182.             }
  183.          AnzahlNormal=PufferMAX;  AnzahlImag=PufferMAX/2;
  184.          AnzahlReal=AnzahlImag+(PufferMAX&1);  Stereo=0;  return;
  185.         }
  186. if(c==1) { AnzahlReal=PufferMAX; for(a=0;a<PufferMAX;a++)real[a]=Puffer[a]; } //Realteil
  187. if(c==2) { AnzahlImag=PufferMAX; for(a=0;a<PufferMAX;a++)imag[a]=Puffer[a]; } //Imaginärteil
  188. AnzahlNormal = AnzahlReal;
  189. if (AnzahlImag<AnzahlReal) AnzahlNormal = AnzahlImag;
  190. }
  191.  
  192.  
  193.  
  194. double Statistic(int o) //1=Real 2=Imag. 3=Reell
  195. {                       //Ermittelung des größten und kleinsten Wertes,
  196. int c,d;                //und der Amplitudenhäufigkeit ( in Puffer[0...maxx] )
  197. long w;                 //zurückgegeben wird der am weitesten von Null entfernte Wert
  198. double b,AmpMAX;
  199. YrangeMAX=-1e99;
  200. YrangeMIN= 1e99;
  201. if((o&1)==1)
  202.    {
  203.     for(w=0;w<AnzahlReal;w++)
  204.        {
  205.         Yoff+=real[w];
  206.         if(real[w]>YrangeMAX)YrangeMAX=real[w];
  207.         if(real[w]<YrangeMIN)YrangeMIN=real[w];
  208.        }
  209.    }
  210. if((o&2)==2)
  211.    {
  212.     for(w=0;w<AnzahlImag;w++)
  213.        {
  214.         Yoff+=imag[w];
  215.         if(imag[w]>YrangeMAX)YrangeMAX=imag[w];
  216.         if(imag[w]<YrangeMIN)YrangeMIN=imag[w];
  217.        }
  218.    }
  219. if(YrangeMAX==YrangeMIN){ if(YrangeMAX>0.0)YrangeMIN=-1e-33; else YrangeMAX=1e-33; }
  220. AmpMAX=fabs(YrangeMAX);    b=fabs(YrangeMIN);
  221. if(b>AmpMAX)AmpMAX=YrangeMIN; else AmpMAX=YrangeMAX;
  222. for(w=0;w<=maxx;w++)Puffer[w]=0.0;             d=(maxx/2);  //Häufigkeit...
  223. if((o&1)==1)
  224.    {
  225.     for(w=0;w<AnzahlReal;w++) { b=real[w]/fabs(AmpMAX)*d+d; Puffer[b]+=1.0; }
  226.    }
  227. if((o&2)==2)
  228.    {
  229.     for(w=0;w<AnzahlImag;w++) { b=imag[w]/fabs(AmpMAX)*d+d; Puffer[b]+=1.0; }
  230.    }
  231. b=0.0001;
  232. for(w=0;w<=maxx;w++)if(Puffer[w]>b)b=Puffer[w];
  233. for(w=0;w<=maxx;w++)Puffer[w]*=(0.9*maxy/b);    //Puffer normieren
  234. return AmpMAX;
  235. }
  236.  
  237.  
  238.  
  239. void Yscale()         //zeige/scaliere die Amplitude_Y (Information)
  240. {
  241. int z=maxy/2,o;
  242. long w;
  243. double r,i,ro,io;
  244. Yoff=0.0;  Grafik(1);   Kill();  setcolor(Farbe[2]);
  245. line(0,maxy,maxx,maxy);  line(maxx/2,0,maxx/2,maxy);
  246. if(Stereo)
  247.    {
  248.     line(0,z,maxx,z);    setcolor(Farbe[1]);            //Y-Häufigkeit real
  249.     r=Statistic(1);      ro=Yoff/((double)AnzahlReal);  Yoff=0.0;
  250.     for(w=0;w<=maxx;w++) if(Puffer[w]>0)line(w,z,w,z-(Puffer[w]/2.0));
  251.     i=Statistic(2);      io=Yoff/((double)AnzahlImag);  //Y-Häufigkeit imag.
  252.     for(w=0;w<=maxx;w++) if(Puffer[w]>0)line(w,maxy,w,maxy-(Puffer[w]/2.0));
  253.     setcolor(Farbe[3]);
  254.     sprintf(AktuellName,"Real Y-Maximum = %lg",r); outtextxy(0,0,AktuellName);
  255.     sprintf(AktuellName,"Imag.Y-Maximum = %lg",i); outtextxy(0,z+9,AktuellName);
  256.     sprintf(AktuellName,"Offset/DC = %lg",ro); outtextxy(maxx/2+9,0,AktuellName);
  257.     sprintf(AktuellName,"Offset/DC = %lg",io); outtextxy(maxx/2+9,z+9,AktuellName);
  258.    }
  259. else
  260.     {
  261.      setcolor(Farbe[1]);  r=Statistic(3);        //Y-Häufigkeit reell zeigen
  262.      ro=Yoff/((double)AnzahlNormal);  io=ro;
  263.      for(w=0;w<=maxx;w++) if(Puffer[w]>0)line(w,maxy,w,maxy-Puffer[w]);
  264.      for(w=0,i=0.0;w<AnzahlReal;w++) i+= (real[w]-ro) * (real[w]-ro);
  265.      for(w=0;      w<AnzahlImag;w++) i+= (real[w]-ro) * (real[w]-ro);
  266.      i=sqrt(i/((double)AnzahlNormal));
  267.      setcolor(Farbe[3]);
  268.      sprintf(AktuellName," Y - Maximum = %lg",r); outtextxy(0,0,AktuellName);
  269.      sprintf(AktuellName,"Peak to Peak = %lg",YrangeMAX-YrangeMIN); outtextxy(0,9,AktuellName);
  270.      sprintf(AktuellName,"Offset/DC = %lg",ro); outtextxy(maxx/2+9,0,AktuellName);
  271.      sprintf(AktuellName,"Y_eff = %lg",i); outtextxy(maxx/2+33,9,AktuellName);
  272.     }
  273. z=inkey(2);                                   //warte auf Taste!
  274. if(z==27) { Grafik(0); return; }              //Escape ?
  275. if((z==323)||(z==324))saveBMP(z-323);         //drucken?
  276.  
  277. settextstyle(0,0,1);   setcolor(Farbe[3]);
  278. outtextxy(maxx/2,18," Esc    Mouse_L: DC=DC    Mouse_R: DC=0");
  279. settextstyle(0,0,4);
  280. if(Stereo)
  281.   {
  282.    outtextxy(162,(1*maxy)/6,"Real & Imag.");
  283.    outtextxy(162,(3*maxy)/6," only Real");
  284.    outtextxy(162,(5*maxy)/6," only Imag.");
  285.    setcolor(Farbe[1]);
  286.    outtextxy(161,(1*maxy)/6-1,"Real & Imag.");
  287.    outtextxy(161,(3*maxy)/6-1," only Real");
  288.    outtextxy(161,(5*maxy)/6-1," only Imag.");
  289.    setcolor(Farbe[2]);
  290.    outtextxy(160,(1*maxy)/6-2,"Real & Imag.");
  291.    outtextxy(160,(3*maxy)/6-2," only Real");
  292.    outtextxy(160,(5*maxy)/6-2," only Imag.");
  293.   }
  294. else
  295.     {
  296.      outtextxy(82,(3*maxy)/6,"New Amplitude ?");
  297.      outtextxy(82,(5*maxy)/6,"    STOP!"); setcolor(Farbe[2]);
  298.      outtextxy(80,(3*maxy)/6-2,"New Amplitude ?");
  299.      outtextxy(80,(5*maxy)/6-2,"    STOP!");
  300.     }
  301. z = GrafikCursor(100);            //AuswahlMENÜ
  302. o = (3*MausY) / maxy;
  303. inkey(0);  Grafik(0);
  304. Zeichensatz();
  305. if(z==27)return;                  //Esc
  306. if((Stereo==0)&&(o!=1))return;    //STOP!
  307. if(o==0) o=3;
  308. if(Stereo==0)o=3;
  309.  
  310. if(z==2)                          //DC=0
  311.         {
  312.          if((o&1)==1)for(w=0;w<AnzahlReal;w++) real[w]-=ro;
  313.          if((o&2)==2)for(w=0;w<AnzahlImag;w++) imag[w]-=io;
  314.         }
  315. r=fabs(Statistic(1));             //no iteration effects
  316. i=fabs(Statistic(2));
  317. if(Stereo==0) i=fabs(Statistic(3));
  318. gotoxy(1,11);
  319. if(o==1)printf("old Real Maximum = %lg\n\n\rnew Real Maximum = ",r);
  320. if(o==2)printf("old Imag.Maximum = %lg\n\n\rnew Imag.Maximum = ",i);
  321. if(o==3)printf("old Maximum = %lg\n\rnew Maximum = ",i);
  322. scanf("%lf",&ro);  fflush(stdin);
  323. if(Stereo)
  324.           {
  325.            if((o&1)==1)for(w=0;w<AnzahlReal;w++) real[w]*=(ro/r);
  326.            if((o&2)==2)for(w=0;w<AnzahlImag;w++) imag[w]*=(ro/i);
  327.           }
  328. else
  329.     {
  330.      for(w=0;w<AnzahlReal;w++) real[w]*=(ro/i);
  331.      for(w=0;w<AnzahlImag;w++) imag[w]*=(ro/i);
  332.     }
  333. }
  334.  
  335.  
  336.  
  337. void ZooM(int o) //0= zoom out,   1= zoom in,   2= zoom in Splitscreen
  338. {               //-1= Y-zoom out,              -2= Y-zoom in
  339. int i,h;
  340. double m,lx,ly,mx,my;
  341. if(o==-1) { m=(or-ur)/2.0;     or+=m;  ur-=m;  }
  342. if(o==-2) { m=(or-ur)/4.0;     or-=m;  ur+=m;  }
  343. if(o==0)
  344.         {
  345.          m=(or-ur)*1.5;     or+=m;  ur-=m;
  346.          m=(rr-lr)*1.5;     rr+=m;  lr-=m;
  347.          if(lr<0.0)lr=0.0;
  348.         }
  349. if(o>0)
  350.        {
  351.         lx=MausX;  lx/=((double)maxx);  lx=lr+lx*(rr-lr);
  352.         ly=MausY;  ly/=((double)maxy);  h=MausY;
  353.         inkey(0);  i=GrafikCursorWindow(MausX,MausY);
  354.         inkey(0);  if(i!=1)return;
  355.  
  356.         mx=MausX;  mx/=((double)maxx);  mx=lr+mx*(rr-lr);
  357.         my=MausY;  my/=((double)maxy);  i=maxy/2;
  358.         if(o==2)
  359.            {
  360.             ly=(    h%(i+1));
  361.             my=(MausY%(i+1));
  362.             if((MausY/i)!=(h/i))
  363.               {
  364.                if((h+MausY)/maxy)ly=ly-i;
  365.                else my=my+i;
  366.               }
  367.             ly/=i,my/=i;
  368.            }
  369.         ly=or-ly*(or-ur);
  370.         my=or-my*(or-ur);
  371.         if(ly<my) ly=or,my=ur;
  372.         if(lx>mx) m=lx,lx=mx,mx=m;
  373.         lr=lx, or=ly, rr=mx, ur=my;
  374.        }
  375. }
  376.  
  377.  
  378.  
  379. void Visual(int STmode) //0=Betrag+Phase, 1=real,2=imag, 3=real&imag, 4=Betrag
  380. {                       //12=Logarithmic
  381.  int i,j,xa,ya,xb,yb,q=(maxy+1)/2;            //Zeigt die Daten am Bildschirm
  382.  long w;
  383.  double b,c,d,AN=((double)(AnzahlNormal-1));
  384.  Grafik(1);
  385.  setviewport(0,0,maxx,maxy,1);        //Start-Skalierung ermitteln...
  386.  YrangeMAX=-1e99;
  387.  YrangeMIN= 1e99;
  388. for(w=0;w<AnzahlReal;w++)
  389.    {
  390.     if(real[w]>YrangeMAX)YrangeMAX=real[w];
  391.     if(real[w]<YrangeMIN)YrangeMIN=real[w];
  392.    }
  393. for(w=0;w<AnzahlImag;w++)
  394.    {
  395.     if(imag[w]>YrangeMAX)YrangeMAX=imag[w];
  396.     if(imag[w]<YrangeMIN)YrangeMIN=imag[w];
  397.    }
  398. if(YrangeMAX==YrangeMIN){ if(YrangeMAX>0.0)YrangeMIN= -0.001; else YrangeMAX=0.001; }
  399. if(FFTflag) Xrange=Samplerate;
  400. else Xrange=((double)AnzahlNormal)/Samplerate;
  401. lr=0.0, rr=Xrange, or=YrangeMAX, ur=YrangeMIN;
  402. ZooM(-1);
  403. if(Stereo)
  404.   {
  405.    LooP:
  406.    Kill();
  407.    if (FFTflag)                        //zeichnet senkrechte Nyqistmarkierung
  408.      {
  409.       c=(Samplerate/2.0-lr)/(rr-lr)*((double)maxx);
  410.       if( (c>=0.0) && (c<=(double)maxx) && (Nykill==0))
  411.          {
  412.           for(i=0;i<=maxy;i+=6)putpixel(c,i,Farbe[3]);
  413.           for(i=0;i<=maxy;i+=4)putpixel(c,i,Farbe[3]);
  414.          }
  415.      }
  416.    c=(or-0.0)/(or-ur)*((double)maxy);
  417.    if( (c>=0.0) && (c<=(double)maxy) )          //zero-lines (Null-Linie)
  418.       {
  419.        if (STmode==3)  //real&imag.
  420.          {                                       c=c/2.0;
  421.            for(i=0;i<=maxx;i+=6)putpixel(i,c,Farbe[3]);
  422.            for(i=0;i<=maxx;i+=6)putpixel(i,q+c,Farbe[3]);
  423.            for(i=0;i<=maxx;i+=4)putpixel(i,c,Farbe[3]);
  424.            for(i=0;i<=maxx;i+=4)putpixel(i,q+c,Farbe[3]);
  425.          }
  426.        else { for(i=0;i<=maxx;i+=6)putpixel(i,c,Farbe[3]); for(i=0;i<=maxx;i+=4)putpixel(i,c,Farbe[3]); }
  427.       }
  428.    if (STmode==3)  //real&imag. (2 Fensterrahmen zeichnen)
  429.       {
  430.        j=Farbe[3];  for(i=0;i<=maxx;i+=8) putpixel(i,q,j);
  431.        for(i=0;i<=maxx;i+=8) { putpixel(i,0,j); putpixel(i,maxy,j); }
  432.        for(i=0;i<=maxy;i+=8) { putpixel(0,i,j); putpixel(maxx,i,j); }
  433.       }
  434.    setcolor(Farbe[3]);
  435.    if(Farbe[19])
  436.      {
  437.       if(STmode&1)outtextxy(maxx-32,0,"real");
  438.       if(STmode==2)outtextxy(maxx-32,0,"imag");
  439.       if(STmode==3)outtextxy(maxx-32,q,"imag");
  440.       if((STmode&3)==0)outtextxy(maxx-40,0,"polar");
  441.       outtextxy(2,maxy-9,"F1");
  442.      }
  443.    i=0,j=0;
  444.    for(w=0;w<AnzahlNormal;w++)        //jetzt wird was angezeigt...
  445.       {
  446.        b=w; b=b/AN*Xrange;
  447.        d=(b-lr)/(rr-lr)*((double)maxx);
  448.        if((d<-32000.0)||(d>32000.0))continue;
  449.        if((STmode&1)==1)                           //Realteil
  450.           {
  451.            c=(or-real[w])/(or-ur)*((double)maxy);
  452.            if ((c>-32000.0)&&(c<32000.0))
  453.              {
  454.               if (i)
  455.                 {
  456.                  setcolor(Farbe[1]);
  457.                  if(STmode==3)
  458.                    {
  459.                     setviewport(0,0,maxx,q-1,1);
  460.                     line(xa,ya/2,d,(c/2.0));
  461.                    }
  462.                  else  line(xa,ya,d,c);
  463.                 }
  464.               i=1;  xa=d;  ya=c;
  465.              }
  466.           }
  467.        if((STmode&2)==2)                           //Imaginärteil
  468.           {
  469.            c=(or-imag[w])/(or-ur)*((double)maxy);
  470.            if((c>-32000.0)&&(c<32000.0))
  471.              {
  472.               if (j)
  473.                 {
  474.                  setcolor(Farbe[2]);
  475.                  if(STmode==3)
  476.                    {
  477.                     setviewport(0,q,maxx,maxy,1);
  478.                     line(xb,yb/2,d,(c/2.0));
  479.                    }
  480.                  else  line(xb,yb,d,c);
  481.                 }
  482.               j=1;  xb=d;  yb=c;
  483.              }
  484.           }
  485.        if((STmode==0)&&(real[w]!=0.0))      //Phase (falls gültig)
  486.           {
  487.            c=0.25*(3.0-atan2(imag[w],real[w])/M_PI)*((double)maxy);
  488.            setcolor(Farbe[2]);
  489.            if(j)line(xb,yb,d,c);
  490.            j=1;   xb=d;   yb=c;
  491.           }
  492.        if((STmode&3)==0)                    //Betrag
  493.           {
  494.            b=imag[w],c=real[w];
  495.            b=sqrt( b*b + c*c );
  496.            if(STmode==12)                   //Betrag logarithmieren?
  497.              {
  498.               if(b>0.0)b=20.0*log10(b); else b=-6000.0;
  499.              }
  500.            c=(or-b)/(or-ur)*((double)maxy);
  501.            if ((c>-32000.0)&&(c<32000.0))
  502.              {
  503.               setcolor(Farbe[1]);
  504.               if(i)line(xa,ya,d,c);
  505.               i=1;   xa=d;   ya=c;
  506.              }
  507.           }
  508.       }
  509.    if(STmode==0)                           //Skalierung der Phase zeigen
  510.                 {
  511.                  setcolor(Farbe[3]);
  512.                  for(i=q;i<maxy;i+=(q/8))  line(maxx-9,i,maxx,i);
  513.                  line(maxx-9,maxy,maxx,maxy);
  514.                  outtextxy(maxx-16,q-3,"π");
  515.                  outtextxy(maxx-17,q+q/2-3,"0");
  516.                  outtextxy(maxx-16,maxy-8,"-π");
  517.                 }
  518.    setviewport(0,0,maxx,maxy,1);
  519.    Loop0:
  520.    inkey(0);  i=GrafikCursorShow(20,(STmode==3)?1:0);      //warte auf Taste
  521.    if(i == 1) { ZooM((STmode==3)?2:1); goto LooP; }        //Zoom IN
  522.    if(i == 2) { ZooM( 0); goto LooP; }                     //Zoom OUT
  523.    if(i=='-') { ZooM(-1); goto LooP; }                   //Y Zoom OUT
  524.    if(i=='+') { ZooM(-2); goto LooP; }                   //Y Zoom IN
  525.    if(i=='r') { STmode=1; goto LooP; }
  526.    if(i=='i') { STmode=2; goto LooP; }
  527.    if(i=='b') { STmode=3; goto LooP; }
  528.    if(i=='a') { STmode=4; goto LooP; }
  529.    if(i=='p') { STmode=0; goto LooP; }
  530.    if(i=='l') { STmode=12; or=3000; ur=-6500; goto LooP; }
  531.    if(i==8)                                    //Fensterinhalt ausschneiden
  532.            {
  533.             c=lr/Xrange*AN;  d=rr/Xrange*AN;
  534.             if(FFTflag)Samplerate/=(AN/(d-c));
  535.             for(AN=c;AN<=d;AN++)
  536.                {
  537.                 w=((long)AN);  or=real[w];  ur=imag[w];
  538.                 w-=((long)c);  real[w]=or;  imag[w]=ur;
  539.                }
  540.             w=(long)(d-c);  w++;
  541.             AnzahlNormal=w;  AnzahlImag=w;  AnzahlReal=w;
  542.            }
  543.    if(i==315) { setcolor(Farbe[3]);
  544.                 outtextxy(3,maxy-9,"F10  F9   A L P R I B   \33 Esc   S X Y Z N   Mouse_L:zoomIN +  - Mouse_R:zoomOUT");
  545.                 goto Loop0;  }
  546.    if((i!=27)&&(i!=8))goto Loop0;
  547.    Grafik(0);
  548.    return;       //ende
  549.   }
  550. Loop1:                                   //zeige Reelle Daten
  551. Kill();     setcolor(Farbe[2]);
  552. c=(or-0.0)/(or-ur)*((double)maxy);
  553. if( (c>=0.0) && (c<=(double)maxy) )line(0,c,maxx,c);     //zeichne Null-Linie
  554. setcolor(Farbe[3]);  if(Farbe[19])outtextxy(2,maxy-9,"F1");
  555. setcolor(Farbe[1]);
  556. i=0;
  557. for(w=0;w<AnzahlNormal;w++)
  558.    {
  559.     b=w; b=b/AN*Xrange;
  560.     d=(b-lr)/(rr-lr)*((double)maxx);
  561.     if((d<-32000.0)||(d>32000.0))continue;
  562.  
  563.     if((w&1))b=imag[w/2]; else b=real[w/2];
  564.     c=(or-b)/(or-ur)*((double)maxy);
  565.     if((c<-32000.0)||(c>32000.0))continue;
  566.     if(i) line(xa,ya,d,c);
  567.     i=1;    xa=d;    ya=c;
  568.    }
  569. Loop2:
  570. inkey(0); i=GrafikCursorShow(20,0);         //warte auf Taste
  571. if(i==1)   { ZooM( 1); goto Loop1; }        //Zoom IN
  572. if(i==2)   { ZooM( 0); goto Loop1; }        //Zoom OUT
  573. if(i=='-') { ZooM(-1); goto Loop1; }      //Y-Zoom OUT
  574. if(i=='+') { ZooM(-2); goto Loop1; }      //Y-Zoom IN
  575. if(i==8)                                  //Fensterinhalt ausschneiden
  576.         {
  577.          c=lr/Xrange*AN;  d=rr/Xrange*AN;
  578.          if(FFTflag)Samplerate/=(AN/(d-c));
  579.          for(AN=c;AN<=d;AN=AN+1.0)
  580.             {
  581.              w=((long)AN);
  582.              if((w&1))b=imag[w/2]; else b=real[w/2];
  583.              w-=((long)c);
  584.              if((w&1))imag[w/2]=b; else real[w/2]=b;
  585.             }
  586.          w=(long)(d-c);  w++;  AnzahlNormal=w;  AnzahlImag=w/2;
  587.          AnzahlReal=AnzahlImag+(w&1);
  588.         }
  589. if(i==315) { setcolor(Farbe[3]);
  590.              outtextxy(3,maxy-9,"F10  F9    \33 Esc    S X Y Z N    Mouse_L:zoomIN    +    -    Mouse_R:zoomOUT");
  591.              goto Loop2;  }
  592. if((i!=27)&&(i!=8))goto Loop2;
  593. Grafik(0);
  594. }
  595.  
  596.  
  597.